package ebcs.database.service.impl.sys;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;


import ebcs.database.bean.sys.PaTimerTask;
import ebcs.database.bean.sys.PaTimerTaskExample;
import ebcs.database.mybatis.dao.sys.PaTimerTaskMapper;
import ebcs.database.service.sys.ITimerManagerService;
import ebcs.scan.common.consts.TimerStatus;

@Service
public class TimerManagerServiceImpl implements ITimerManagerService {
	private Logger logger = Logger.getLogger(TimerManagerServiceImpl.class);
	@Autowired
	private PaTimerTaskMapper timerDao;
	
	@Override
	@Cacheable(value="timerList")
	public List<PaTimerTask> searchAllTimerList() {
		PaTimerTaskExample exam =  new PaTimerTaskExample();
		PaTimerTaskExample.Criteria cit =  exam.createCriteria();
		cit.andTaskOnoffEqualTo(TimerStatus.TimerOn.getValue());
		return this.timerDao.selectByExample(exam);
	}
	
	
	@CacheEvict(value = "timerList", allEntries=true)
	public void evictTimerListCache(){
		logger.info("doClearTimerTask ......");
	}
	
	@CacheEvict(value = "timerList", allEntries=true)
	public int addTimerTask(PaTimerTask task) {
		return this.timerDao.insert(task);
	}


	@Override
	public int updateTimerTask(PaTimerTask timerTask) {
		// TODO Auto-generated method stub
		return this.timerDao.updateByPrimaryKeySelective(timerTask);
	}


}
